use crate::model::fiof::User;
use mongodb::{
    bson::{self, Document},
    Client, Collection, Cursor,
};
use sqlx::{self, MySql, Pool};
use std::sync::Arc;

const DB_NAME: &str = "best_data_mongo";
const FIOF_COLL_NAME: &str = "fiof";

pub struct FifoSDao {
    pub pool: Arc<Pool<MySql>>,
    pub mongo_client: Client,
}

impl FifoSDao {
    pub fn new(pool: Arc<Pool<MySql>>, mongo_client: Client) -> FifoSDao {
        FifoSDao { pool, mongo_client }
    }

    pub async fn get_fiof_info(&self) -> Option<Document> {
        // sqlx::query_as::<MySql, User>("select * from fiof")
        //     .fetch_all(&*self.pool)
        //     .await

        let collection = self
            .mongo_client
            .database(DB_NAME)
            .collection::<Document>(FIOF_COLL_NAME);

        let info = collection.find_one(bson::doc! {}, None).await.unwrap();
        info
    }
}
